/*     */ package com.zimbra.cs.server;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.NetUtil;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.net.ServerSocket;
/*     */ import java.nio.channels.ServerSocketChannel;
/*     */ import java.util.ArrayList;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class ServerConfig
/*     */ {
/*     */   private String protocol;
/*     */   private boolean ssl;
/*     */   private static final int DEFAULT_SHUTDOWN_TIMEOUT = 10;
/*     */   private static final int DEFAULT_MAX_THREADS = 1;
/*     */   private static final int DEFAULT_MAX_IDLE_TIME = 600;
/*     */   private static final int DEFAULT_MAX_CONNECTIONS = 10;
/*     */   private static final int DEFAULT_WRITE_CHUNK_SIZE = 8192;
/*     */   private static final int DEFAULT_WRITE_TIMEOUT = 10;
/*     */   private static final int DEFAULT_THREAD_KEEP_ALIVE_TIME = 120;
/*  42 */   private static final int DEFAULT_MAX_WRITE_QUEUE_SIZE = LC.nio_max_write_queue_size.intValue();
/*     */   
/*     */   public ServerConfig(String protocol, boolean ssl) {
/*  45 */     this.protocol = protocol;
/*  46 */     this.ssl = ssl;
/*     */   }
/*     */   
/*     */   public String getServerName() {
/*  50 */     return LC.zimbra_server_hostname.value();
/*     */   }
/*     */   
/*     */   public String getServerVersion() {
/*  54 */     return null;
/*     */   }
/*     */   
/*     */   public String getBindAddress() {
/*  58 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public abstract int getBindPort();
/*     */   
/*     */ 
/*     */   public abstract Log getLog();
/*     */   
/*     */ 
/*     */   public int getMaxIdleTime()
/*     */   {
/*  71 */     return 600;
/*     */   }
/*     */   
/*     */   public int getMaxThreads() {
/*  75 */     return 1;
/*     */   }
/*     */   
/*     */   public String getProtocol() {
/*  79 */     return this.protocol;
/*     */   }
/*     */   
/*     */   public boolean isSslEnabled() {
/*  83 */     return this.ssl;
/*     */   }
/*     */   
/*     */   public String getGreeting() {
/*  87 */     return getDescription() + " ready";
/*     */   }
/*     */   
/*     */   public String getGoodbye() {
/*  91 */     return getDescription() + " closing connection";
/*     */   }
/*     */   
/*     */ 
/*     */   public String getConnectionRejected()
/*     */   {
/*  97 */     return null;
/*     */   }
/*     */   
/*     */   public String getDescription() {
/* 101 */     StringBuilder sb = new StringBuilder();
/* 102 */     String name = getServerName();
/* 103 */     if ((name != null) && (!name.isEmpty())) {
/* 104 */       sb.append(name).append(' ');
/*     */     }
/* 106 */     sb.append("Zimbra ");
/* 107 */     String version = getServerVersion();
/* 108 */     if ((version != null) && (!version.isEmpty())) {
/* 109 */       sb.append(version).append(' ');
/*     */     }
/* 111 */     return getProtocol() + " server";
/*     */   }
/*     */   
/*     */   public String[] getMailboxdSslProtocols() {
/* 115 */     return getConfigAttr("zimbraMailboxdSSLProtocols");
/*     */   }
/*     */   
/*     */   public String[] getSslExcludedCiphers() {
/* 119 */     return getConfigAttr("zimbraSSLExcludeCipherSuites");
/*     */   }
/*     */   
/*     */   public String[] getSslIncludedCiphers() {
/* 123 */     return getConfigAttr("zimbraSSLIncludeCipherSuites");
/*     */   }
/*     */   
/*     */   private String[] getConfigAttr(String key) {
/*     */     try {
/* 128 */       return Provisioning.getInstance().getConfig().getMultiAttr(key);
/*     */     } catch (ServiceException e) {
/* 130 */       getLog().warn("Unable to get global attribute: " + key, e); }
/* 131 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public int getShutdownTimeout()
/*     */   {
/* 142 */     return 10;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public int getMaxConnections()
/*     */   {
/* 151 */     return 10;
/*     */   }
/*     */   
/*     */   public int getWriteChunkSize() {
/* 155 */     return 8192;
/*     */   }
/*     */   
/*     */   public int getWriteTimeout() {
/* 159 */     return 10;
/*     */   }
/*     */   
/*     */   public int getThreadKeepAliveTime() {
/* 163 */     return 120;
/*     */   }
/*     */   
/*     */   public int getNioMaxWriteQueueDelay() {
/* 167 */     return getWriteTimeout() * 1000;
/*     */   }
/*     */   
/*     */   public int getNioMaxWriteQueueSize() {
/* 171 */     return DEFAULT_MAX_WRITE_QUEUE_SIZE;
/*     */   }
/*     */   
/*     */   public ServerSocket getServerSocket() throws ServiceException
/*     */   {
/* 176 */     return isSslEnabled() ? NetUtil.getSslTcpServerSocket(getBindAddress(), getBindPort(), getSslExcludedCiphers(), getSslIncludedCiphers(), getMailboxdSslProtocols()) : NetUtil.getTcpServerSocket(getBindAddress(), getBindPort());
/*     */   }
/*     */   
/*     */   public ServerSocketChannel getServerSocketChannel()
/*     */     throws ServiceException
/*     */   {
/* 182 */     return NetUtil.getNioServerSocket(getBindAddress(), getBindPort()).getChannel();
/*     */   }
/*     */   
/*     */   protected String getAttr(String key, String defaultValue) {
/*     */     try {
/* 187 */       return getLocalServer().getAttr(key, defaultValue);
/*     */     } catch (ServiceException e) {
/* 189 */       getLog().warn("Unable to get server attribute: " + key, e); }
/* 190 */     return defaultValue;
/*     */   }
/*     */   
/*     */   protected int getIntAttr(String key, int defaultValue)
/*     */   {
/*     */     try {
/* 196 */       return getLocalServer().getIntAttr(key, defaultValue);
/*     */     } catch (ServiceException e) {
/* 198 */       getLog().warn("Unable to get server attribute: " + key, e); }
/* 199 */     return defaultValue;
/*     */   }
/*     */   
/*     */   protected boolean getBooleanAttr(String key, boolean defaultValue)
/*     */   {
/*     */     try {
/* 205 */       return getLocalServer().getBooleanAttr(key, defaultValue);
/*     */     } catch (ServiceException e) {
/* 207 */       getLog().warn("Unable to get server attribute: " + key, e); }
/* 208 */     return defaultValue;
/*     */   }
/*     */   
/*     */   protected Server getLocalServer() throws ServiceException
/*     */   {
/* 213 */     return Provisioning.getInstance().getLocalServer();
/*     */   }
/*     */   
/*     */   protected Config getGlobalConfig() throws ServiceException {
/* 217 */     return Provisioning.getInstance().getConfig();
/*     */   }
/*     */   
/*     */   public boolean isServiceEnabled() {
/*     */     try {
/* 222 */       return Provisioning.getInstance().getLocalServer().getBooleanAttr("zimbraUserServicesEnabled", true);
/*     */     }
/*     */     catch (ServiceException e) {
/* 225 */       getLog().error("Unabled to determine the service availability", e); }
/* 226 */     return false;
/*     */   }
/*     */   
/*     */   public String[] getThottleIgnoredHosts() throws ServiceException
/*     */   {
/* 231 */     return getAddrListCsv(getLocalServer().getMultiAttr("zimbraThrottleSafeHosts"));
/*     */   }
/*     */   
/*     */   public String[] getThrottleWhitelist() throws ServiceException {
/* 235 */     return getAddrListCsv(getLocalServer().getMultiAttr("zimbraThrottleWhitelist"));
/*     */   }
/*     */   
/*     */   public static String[] getAddrListCsv(String[] addrCsvs)
/*     */   {
/* 240 */     ArrayList<String> addrList = new ArrayList(addrCsvs.length);
/* 241 */     for (String addrCsv : addrCsvs) {
/* 242 */       if ((addrCsv != null) && (addrCsv.length() > 0)) {
/* 243 */         String[] addrs = addrCsv.split(",");
/* 244 */         for (String addr : addrs) {
/* 245 */           addrList.add(addr);
/*     */         }
/*     */       }
/*     */     }
/* 249 */     return (String[])addrList.toArray(new String[addrList.size()]);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/server/ServerConfig.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */